<?PHP
if (!session_start()) { session_start(); };
/*if (!isset($_SESSION['lgnapproved'])) {
	die(header('Location: login.php'));
}*/

include("functions.php");
include("cnnxn.php");
connect();

if (isset($_GET['rid'])) {
	$SQLgrd='SELECT * FROM Results WHERE ResultID='.$_GET['rid'].';';
	$sendgrd=mysqli_query($db,$SQLgrd) or die(mysqli_error($db));
	$RSgrd=mysqli_fetch_object($sendgrd);
	
	$SQLget='SELECT * FROM Events WHERE EventID='.$RSgrd->EventID.';';
	$sendget=mysqli_query($db,$SQLget) or die(mysqli_error($db));
	$RSget=mysqli_fetch_object($sendget);
	
	$newnumberOfTeams=$RSget->NumberOfTeams-1;
	$SQLupet='UPDATE Events SET NumberOfTeams='.$newnumberOfTeams.' WHERE EventID='.$RSgrd->EventID.';';
	$sendupet=mysqli_query($db,$SQLupet) or die(mysqli_error($db));
	
	$SQLdel='DELETE FROM Results WHERE ResultID='.$_GET['rid'].';';
	//print $SQLdel;
	$sendit_del=mysqli_query($db,$SQLdel) or die(mysqli_error($db));
	
	mysqli_close($db);
	
	die(header("Location: Results_viewall.php?tid=".$_GET['tid']."&eid=".$_GET['eid'].'&gen='.$_GET['gen'].'&div='.$_GET['div']));
}
?>